perf(daemon): cache getKnownRigs() per tick and atomic rigs.json writes#3489
Open
jw409 wants to merge 1 commit intogastownhall:mainfrom
Open
perf(daemon): cache getKnownRigs() per tick and atomic rigs.json writes#3489jw409 wants to merge 1 commit intogastownhall:mainfrom
jw409 wants to merge 1 commit intogastownhall:mainfrom
Conversation
…writes Cache the result of getKnownRigs() within each heartbeat tick to eliminate 10+ redundant reads of mayor/rigs.json per cycle. The cache is invalidated at the start of each heartbeat so changes are picked up between ticks. Replace direct os.WriteFile calls for rigs.json in the doctor package with util.AtomicWriteFile (write-to-temp-then-rename) to prevent concurrent readers from seeing zero-byte or partial content. Fixes gastownhall#3466
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getKnownRigs()result per heartbeat tick instead of readingmayor/rigs.jsonon every call — eliminates 10+ redundant disk reads per tickos.WriteFileonrigs.jsonin the doctor package withutil.AtomicWriteFile(write-to-temp-then-rename) — prevents concurrent readers from seeing zero-byte or partial contentChanges
internal/daemon/daemon.go— AddcachedKnownRigs/knownRigsCachedfields toDaemonstruct;getKnownRigs()returns cached result on subsequent calls within the same tick. Cache is invalidated at the start of eachheartbeat()call. All access is single-goroutine (the main for/select loop), so no mutex needed.internal/doctor/workspace_check.go— Replace twoos.WriteFilecalls forrigs.jsonwithutil.AtomicWriteFile, which already exists in the codebase and uses write-to-temp-then-rename.Notes
util.AtomicWriteFilehelper (andcopyFileIfNewerinsession/registry.go) already use the temp-file-then-rename pattern. This PR extends that pattern to the two remaining non-atomic write sites in the doctor package.go buildlocally (go.mod requires go 1.25.8, local toolchain is 1.25.2). Changes are minimal and mechanically correct — CI will validate.Fixes #3466
🇺🇸 Reid Wiseman — Commander
🇺🇸 Victor Glover — Pilot
🇺🇸 Christina Koch — Mission Specialist
🇨🇦 Jeremy Hansen — Mission Specialist
Artemis II. Open source for all — on this planet and beyond it.